/*
    数组最值
 */
public class ArrMaxMin {
    public static void main(String[] args){

        int[] arr = {2,1,5,4,2};
        int maxIndex = 0, minIndex = 0;
        int max,min;

        for(int i = 0;i < arr.length;i++){
            if(arr[i] > arr[maxIndex]){
                maxIndex = i;
            }
            if(arr[i] < arr[minIndex]) {
                minIndex = i;
            }
        }

        max = arr[maxIndex];
        min = arr[minIndex];

        System.out.println(max + "为最大值");
        System.out.println(min + "为最小值");
    }
}
